// pages/success/lottery_success/lottery_success.js
const config = require('../../../config.js')
const $ = require('../../../utils/utils.js')
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        gift_content: "",
        hdUserId: "",
        usertoken: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */


    onLoad: function (options) {
        let that = this
        this.setData({
            gift_content: options.gift_content
        })

        if (options.usertoken) {
            this.setData({
                usertoken: options.usertoken
            })
            wx.setStorageSync('usertoken', options.usertoken)
            wx.setStorageSync('userid', options.userid)
        }

        that.getShareInfo()
        wx.hideShareMenu()
    },

    getShareInfo: function () {
        let that = this
        let params = {
            usertoken: wx.getStorageSync('usertoken'),
            userid : wx.getStorageSync('userid')
        }


        $.post(config.activityShareInfo, params).then(data => {
            console.log(data)
            wx.showShareMenu()
            that.setData({
                hdUserId: data.detail.hdUserId
            })
        }).catch(error => {

        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    tapContinueBtn: function () {
        wx.navigateBack()
    },


    toHomePage: function () {
        wx.reLaunch({
            url: config.page.index
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: '哇！一次抽奖机会砸中你',
            path: config.page.activityLottery + '?hdUserId=' + this.data.hdUserId,
            imageUrl: 'http://wdb007.oss-cn-hangzhou.aliyuncs.com/wxapp/images/lottery_share.png',
            success: function (share) {
                // 转发成功
                console.log("分享", path);
            },
            fail: function (res) {
                // 转发失败
            }
        }
    }
})